import { defineStore } from 'pinia'
import request from '@/extensions/axios'
export const useUserStore = defineStore('menus', {
  state:  () => {
    return {
      menus:[],
      loading:false,
      error:null,
      loaded:false,
    }
  },
  getters: {
 
  },
  actions: {
    async fetchMenus(force=false) {
      if(!force && this.loaded){
        return
      }
      if(this.loading){
        return;
      }
      this.loading = true;
      const response = await request.get('/open/menu')
      this.loading = false;
      if(response.status === 200 &&
          response.data &&
          typeof response.data.menus!="undefined"
      ){
        this.menus = response.data.menus;
        this.loaded = true;
      }
    }
  }
})